home *** CD-ROM | disk | FTP | other *** search
- /*----------------------------------------------------------------------------
-
- menus.c
-
- This module manges the menus.
-
- Copyright © 1994-1995, Northwestern University.
-
- ----------------------------------------------------------------------------*/
-
- #include <stdio.h>
-
- #include "glob.h"
- #include "menus.h"
- #include "menuutil.h"
- #include "strutil.h"
- #include "wind.h"
-
-
-
- /*----------------------------------------------------------------------------
- SetMenusTo
-
- Set the menus to a given state.
-
- Entry: newAppleMenuState = new Apple menu enable/disable flags.
- newFileMenuState = new File menu enable/disable flags.
- newEditMenuState = new Edit menu enable/disable flags.
- newNewsMenuState = new News menu enable/disable flags.
- newSpecialMenuState = new Special menu enable/disable flags.
- newWindMenuState = new Windows menu enable/disable flags.
- ----------------------------------------------------------------------------*/
-
- void SetMenusTo (
- unsigned long newAppleMenuState,
- unsigned long newFileMenuState,
- unsigned long newEditMenuState,
- unsigned long newNewsMenuState,
- unsigned long newSpecialMenuState,
- unsigned long newWindMenuState)
- {
- Boolean r0, r1, r2, r3 ,r4, r5;
- static unsigned long appleMenuState = 0;
- static unsigned long fileMenuState = 0;
- static unsigned long editMenuState = 0;
- static unsigned long newsMenuState = 0;
- static unsigned long specialMenuState = 0;
- static unsigned long windMenuState = 0;
-
- r0 = AdjustOneMenu(kAppleMenu, 31, &appleMenuState, newAppleMenuState);
- r1 = AdjustOneMenu(kFileMenu, kNumFileMenuItems, &fileMenuState, newFileMenuState);
- r2 = AdjustOneMenu(kEditMenu, kNumEditMenuItems, &editMenuState, newEditMenuState);
- r3 = AdjustOneMenu(kNewsMenu, kNumNewsMenuItems, &newsMenuState, newNewsMenuState);
- r4 = AdjustOneMenu(kSpecialMenu, kNumSpecialMenuItems, &specialMenuState, newSpecialMenuState);
- r5 = AdjustOneMenu(kWindMenu, kNumWindMenuItems, &windMenuState, newWindMenuState);
- if (r0 || r1 || r2 || r3 || r4 || r5) DrawMenuBar();
- }
-
-
-
- /*----------------------------------------------------------------------------
- SetWindowsMenuShowHideFullGroupList
-
- Set the Windows menu command to "Show Full Group List" or
- "Hide Full Group List".
-
- Entry: show = true to set to "Show Full Group List"
- = false to set to "Hide Full Group List"
- ----------------------------------------------------------------------------*/
-
- void SetWindowsMenuShowHideFullGroupList (Boolean show)
- {
- MenuHandle windMenu;
- Str255 str;
-
- windMenu = GetMenuHandle(kWindMenu);
- GetPString(show ? kStrShowFullGroupList : kStrHideFullGroupList, str);
- SetMenuItemText(windMenu, kShowHideFullGroupListItem, str);
- }
-
-
-
- /*----------------------------------------------------------------------------
- SetEditMenuShowHideDetails
-
- Set the Edit menu command to "Show Details" or "Hide Details".
-
- Entry: show = true to set to "Show Details"
- = false to set to "Hide Details"
- ----------------------------------------------------------------------------*/
-
- void SetEditMenuShowHideDetails (Boolean show)
- {
- MenuHandle editMenu;
- Str255 str;
-
- editMenu = GetMenuHandle(kEditMenu);
- GetPString(show ? kStrShowHeader : kStrHideHeader, str);
- SetMenuItemText(editMenu, kShowHideDetailsItem, str);
- }
-
-
-
- /*----------------------------------------------------------------------------
- AdjustExtractBinariesCommand
-
- Adjust the "Extract Binaries" command in the "Special" menu.
- The command should end in an ellipsis iff there is no default
- download folder configured.
- ----------------------------------------------------------------------------*/
-
- void AdjustExtractBinariesCommand (void)
- {
- MenuHandle specialMenu;
- Str255 str;
- unsigned char len;
-
- specialMenu = GetMenuHandle(kSpecialMenu);
- GetMenuItemText(specialMenu, kExtractBinariesItem, str);
- len = str[0];
- if (gPrefs.savedBinDefaultFolder && str[len] == '.') {
- str[0] = len-3;
- SetMenuItemText(specialMenu, kExtractBinariesItem, str);
- } else if (!gPrefs.savedBinDefaultFolder && str[len] != '.') {
- str[0] = len+3;
- str[len+1] = str[len+2] = str[len+3] = '.';
- SetMenuItemText(specialMenu, kExtractBinariesItem, str);
- }
- }
-
-
-
- /*----------------------------------------------------------------------------
- AdjustCycleWindowsCommand
-
- Adjust the "Cycle Windows" command in the "Windows" menu.
- "Cycle Windows" should be enabled iff more than one visible window is open.
- ----------------------------------------------------------------------------*/
-
- void AdjustCycleWindowsCommand (void)
- {
- WindowPtr wind;
- WindowPeek peek;
- short numVis = 0;
- MenuHandle windowsMenu;
-
- wind = FrontWindow();
- while (wind != nil) {
- peek = (WindowPeek)wind;
- if (peek->visible) {
- numVis++;
- if (numVis >= 2) break;
- }
- wind = (WindowPtr)peek->nextWindow;
- }
- windowsMenu = GetMenuHandle(kWindMenu);
- if (numVis >= 2) {
- EnableItem(windowsMenu, kCycleWindowsItem);
- } else {
- DisableItem(windowsMenu, kCycleWindowsItem);
- }
- }
-
-
-
- /*----------------------------------------------------------------------------
- AdjustMenuHelpBalloons
-
- Adjust the main menu bar help balloons.
-
- Entry: term = true if program is terminating, in which case the
- menu help balloons are reset to their default state.
-
- There are four sets of 'hmnu' resources for the main menus. This
- function is called at idle time to switch between the sets when
- necessary.
-
- Normal set: resource id = menu id.
-
- Startup bad set: resource id = 1000 + menu id.
- Used when there is a problem starting up.
-
- Dialog set: resource id = 2000 + menu id.
- Used when a dialog or alert is on the screen.
-
- Busy set: resource id = 3000 + menu id.
- Used during long operations.
-
- This function also makes sure the menus are disabled if Balloon
- help is enabled and there is a long operation in progress.
- ----------------------------------------------------------------------------*/
-
- void AdjustMenuHelpBalloons (Boolean term)
- {
- TWindowKind kind;
- static short curState = 0;
- short newState, i;
-
- if (term) {
- newState = 0;
- } else {
- kind = GetMyWindowKind(FrontWindow());
- if (kind == kDialog) {
- newState = 2000;
- } else if (gLongOperation) {
- newState = 3000;
- if (HMGetBalloons())
- SetMenusTo(kAppleOnlyAboutDisabled, 0, 0, 0, 0, 0);
- } else if (gStartupOK) {
- newState = 0;
- } else {
- newState = 1000;
- }
- }
- if (curState == newState) return;
- for (i = kAppleMenu; i <= kWindMenu; i++)
- HMSetMenuResID(i, newState == 0 ? -1 : i + newState);
- curState = newState;
- }
-